﻿@using BusinessLibrary
@model IEnumerable<MMSWebsite.Models.Asset.Asset>

@{
    ViewBag.Title = "Detail & Asset";
    bool finishValuation = false, confirmLoan = false; 
    if(Model.Count() != 0)
    {
        finishValuation = true;
        confirmLoan = true;
        if (Model.First().Customer.FinishedDay != null)
        {
            finishValuation = false;
        }
    }
}
<style type="text/css">
    label {
        color:gold
    }
</style>
<ul data-role="listview"style="margin: auto" >
    @foreach (var item in Model)
    {
        <li style="border-radius: 10px">
            @Html.Label("Name : ") @item.AssetName <br>
            @Html.Label("Type : ") @item.AssetType.name<br>
            @Html.Label("Status : ") @item.Status.Last().Status.value<br>
            
            @if(item.Valuation.Value == null)
             {//Check FV finish Valuation for all Asset
                 finishValuation = false;
             }
            @Html.Label("Valuation : ") @Html.DisplayFor(model=> item.Valuation.Value)<br>
            @if(item.Loan.ValueLoan == null)
            {//Check FV finish Loan&rate for all Asset
                confirmLoan = false;
            }
            @Html.Label("Loan : ") @Html.DisplayFor(model=>item.Loan.ValueLoan)<br>
            @Html.Label("Rate : ") @Html.DisplayFor(model=>item.Rate.ValueRate)<br>
            <input type="button" data-theme="e" data-icon="arrow-r" value="Valuation" onclick="location.href = '@Url.Action("Edit", "Asset", new { assetId = item.Id })'">
        </li>
    }
</ul>

<div style="text-align: center">
    @if (finishValuation)
    {
        <input type="button" onclick="location.href = '@Url.Action("FVFinish", "Asset", new { cusId = Model.First().Customer.Id })'" value="Finish Valuation" />
    }
    if(confirmLoan)
    {
        <input type="button" onclick="location.href = '@Url.Action("RefuseLoan", "Asset", new { assetId = Model.First().Id })'" value="Refuse Loan" />
        <input type="button" onclick="location.href = '@Url.Action("ConfirmLoan", "Asset", new { assetId = Model.First().Id })'" value="Confirm Loan" />
        
    }
</div>
  